/*-----------------------------------------------------------------------------
	The contents of this file are subject to the Mozilla Public License
	Version 1.1 (the "License"); you may not use this file except in
	compliance with the License. You may obtain a copy of the License at
	http://www.mozilla.org/MPL/
	
	Software distributed under the License is distributed on an "AS IS"
	basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
	License for the specific language governing rights and limitations
	under the License.
	
	The Original Code is Fever Framework code.
	
	The Initial Developer of the Original Code is Romain Ecarnot.
	Portions created by Initial Developer are Copyright (C) 2006
	the Initial Developer. All Rights Reserved.
	
	Contributor(s):
	
	Unless required by applicable law or agreed to in writing, software
	distributed under the License is distributed on an "AS IS" BASIS,
	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
	See the License for the specific language governing permissions and
	limitations under the License.
-----------------------------------------------------------------------------*/

import com.bourre.structures.Rectangle;

import fever.Fever;

import flash.display.BitmapData;

/**
 * Stores an application screenshot in a {@code BitmapData} object. 
 * 
 * <p>Use contructor parameter {@code includeOverlay} or {@link #setOverLayEnabled()} 
 * to include overlay layer to screenshot.<br />
 * Default don't use this overlay layer, so every object on this layer 
 * ( FvAlert dialog, FvFilechooser dialog, ... ) are not shoot.
 * 
 * <p>Take a look at {@link fever.display.FeverStage} to see <strong>Fever layer 
 * managment</strong>
 * 
 * @see fever.display.FeverStage
 * @see fever.display.ModalScreen
 * 
 * @author Romain Ecarnot
 */
class fever.display.ScreenShot
{
	//-------------------------------------------------------------------------
	// Private properties
	//-------------------------------------------------------------------------
	
	private var _data : BitmapData;
	private var _target : MovieClip;
	private var _includeOverlay : Boolean;
	
	
	//-------------------------------------------------------------------------
	// Public API
	//-------------------------------------------------------------------------
	
	/**
	 * Constructor.
	 * 
	 * @param target MovieClip content to shoot. ( default use 
	 * {@link fever.display.FeverStage#level0} target.
	 * @param includeOverlay {@code true} to shoot overlay layer. ( default 
	 * {@code false}
	 */
	public function ScreenShot( target : MovieClip, includeOverlay : Boolean )
	{
		_target = ( target ) ? target : Fever.stage.level0;
		_includeOverlay = ( includeOverlay ) ? true : false;
	}
	
	/**
	 * Updates screenshot.
	 * 
	 * <p>Hides {@link fever.display.FeverStage#overlayLevel} layer 
	 * before updating.
	 */
	public function update() : Void
	{
		if( !_includeOverlay ) Fever.stage.overlayLevel._visible = false;
		Fever.stage.cursorLevel._visible = false;
		
		dispose();
		
		var size : Rectangle = Fever.application.getSize();
		
		_data = new BitmapData( size.width, size.height, false );
		_data.draw( _target );
		
		Fever.stage.cursorLevel._visible = true;
		Fever.stage.overlayLevel._visible = true;
	}
	
	/**
	 * Defines if overlay layer can be shoot or not.
	 */
	public function setOverLayEnabled( enabled : Boolean ) : Void
	{
		_includeOverlay = ( enabled ) ? true : false;	
	}
	
	/**
	 * Returns {@code true} if overlay layer can be shoot.
	 */
	public function isOverlayEnabled() : Boolean
	{
		return _includeOverlay;	
	}
	
	/**
	 * Clears screen bitmap data.
	 */
	public function dispose() : Void
	{
		_data.dispose();	
	}
	
	/**
	 * Returns the {@code BitmapData} data.
	 */
	public function getData() : BitmapData
	{
		return _data;	
	}
}